//
//  MainTabBar.swift
//  Status
//
//  Created by 花轮 on 15/5/10.
//  Copyright (c) 2015年 花轮. All rights reserved.
//

import UIKit

class MainTabBar: UITabBar {
    override func layoutSubviews() {
        super.layoutSubviews()
        
        let btnCount = 5
        let w = self.bounds.size.width / CGFloat(btnCount)
        let h = self.bounds.size.height
        
        let frame = CGRectMake(0, 0, w, h)
        
//        println(self.subviews as NSArray)
        var index:CGFloat = 0
        for v in subviews as! [UIView]
        {
            if v is UIControl && !(v is UIButton)
            {
                v.frame = CGRectMake(index*w, 0, w, h)
                
                
                index += (index == 1) ? 2 : 1
            }
        }
        
        self.composeedButton.frame = CGRectOffset(frame, 2*w, 0)
    }
    lazy var composeedButton: UIButton = {
        let btn = UIButton()
        
        btn.setImage(UIImage(named: "tabbar_compose_icon_add"), forState: UIControlState.Normal)
        btn.setImage(UIImage(named: "tabbar_compose_icon_add_highlighted"), forState: UIControlState.Highlighted)
        btn.setBackgroundImage(UIImage(named: "tabbar_compose_button"), forState: UIControlState.Normal)
        btn.setBackgroundImage(UIImage(named: "tabbar_compose_button_highlighted"), forState: UIControlState.Highlighted)
        
        self.addSubview(btn)
        
        return btn
    }()
}
